home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Library / Manuels & Misc / Assembly / AOA.ZIP / CH05 / PGM5_2.ASM < prev    next >
Encoding:
Assembly Source File  |  1994-10-09  |  2.4 KB  |  109 lines

  1. ; Using Pointer Variables in an Assembly Language Program
  2. ;
  3. ; This short sample program demonstrates the use of pointers in
  4. ; an assembly language program.
  5. ;
  6. ; Randall Hyde
  7.  
  8. dseg        segment    para public 'data'
  9.  
  10.  
  11. ; Some variables we will access indirectly (using pointers):
  12.  
  13. J        word    0, 0, 0, 0
  14. K        word    1, 2, 3, 4
  15. L        word    5, 6, 7, 8
  16.  
  17. ; Near pointers are 16-bits wide and hold an offset into the current data
  18. ; segment (dseg in this program).  Far pointers are 32-bits wide and hold
  19. ; a complete segment:offset address.  The following type definitions let
  20. ; us easily create near and far pointers
  21.  
  22. nWrdPtr        typedef    near ptr word
  23. fWrdPtr        typedef    far ptr word
  24.  
  25.  
  26. ; Now for the actual pointer variables:
  27.  
  28. Ptr1        nWrdPtr    ?
  29. Ptr2            nWrdPtr    K        ;Initialize with K's address.
  30. Ptr3        fWrdPtr    L        ;Initialize with L's segmented adrs.
  31.  
  32. dseg        ends
  33.  
  34.  
  35.  
  36. cseg        segment    para public 'code'
  37.         assume    cs:cseg, ds:dseg
  38.  
  39. Main        proc
  40.         mov    ax, dseg    ;These statements are provided by
  41.         mov    ds, ax        ; shell.asm to initialize the
  42.         mov    es, ax        ; segment register.
  43.  
  44.  
  45. ; Initialize Ptr1 (a near pointer) with the address of the J variable.
  46.  
  47.         lea    ax, J
  48.         mov    Ptr1, ax
  49.  
  50. ; Add the four words in variables J, K, and L together using pointers to
  51. ; these variables:
  52.  
  53.         mov    bx, Ptr1    ;Get near ptr to J's 1st word.
  54.         mov    si, Ptr2    ;Get near ptr to K's 1st word.
  55.         les    di, Ptr3    ;Get far ptr to L's 1st word.
  56.  
  57.  
  58.  
  59.         mov    ax, ds:[si]    ;Get data at K+0.
  60.         add    ax, es:[di]    ;Add in data at L+0.
  61.         mov    ds:[bx], ax    ;Store result to J+0.
  62.  
  63.         add    bx, 2        ;Move to J+2.
  64.         add    si, 2        ;Move to K+2.
  65.         add    di, 2        ;Move to L+2.
  66.  
  67.  
  68.  
  69.         mov    ax, ds:[si]    ;Get data at K+2.
  70.         add    ax, es:[di]    ;Add in data at L+2.
  71.         mov    ds:[bx], ax    ;Store result to J+2.
  72.  
  73.         add    bx, 2        ;Move to J+4.
  74.         add    si, 2        ;Move to K+4.
  75.         add    di, 2        ;Move to L+4.
  76.  
  77.  
  78.  
  79.         mov    ax, ds:[si]    ;Get data at K+4.
  80.         add    ax, es:[di]    ;Add in data at L+4.
  81.         mov    ds:[bx], ax    ;Store result to J+4.
  82.  
  83.         add    bx, 2        ;Move to J+6.
  84.         add    si, 2        ;Move to K+6.
  85.         add    di, 2        ;Move to L+6.
  86.  
  87.  
  88.  
  89.         mov    ax, ds:[si]    ;Get data at K+6.
  90.         add    ax, es:[di]    ;Add in data at L+6.
  91.         mov    ds:[bx], ax    ;Store result to J+6.
  92.  
  93.  
  94.  
  95. Quit:        mov    ah, 4ch        ;Magic number for DOS
  96.         int    21h        ; to tell this program to quit.
  97. Main        endp
  98.  
  99. cseg        ends
  100.  
  101. sseg        segment    para stack 'stack'
  102. stk        byte    1024 dup ("stack   ")
  103. sseg        ends
  104.  
  105. zzzzzzseg    segment    para public 'zzzzzz'
  106. LastBytes    byte    16 dup (?)
  107. zzzzzzseg    ends
  108.         end    Main
  109.